package com.ruoyi.system.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.domain.AuditRoute;
import org.apache.ibatis.annotations.Param;

/**
 * 审核路径实例（节点级）Mapper接口
 * 
 * @author ruoyi
 * @date 2025-11-07
 */
public interface AuditRouteMapper extends BaseMapper<AuditRoute>
{
    /**
     * 查询审核路径实例（节点级）
     * 
     * @param auditRouteId 审核路径实例（节点级）主键
     * @return 审核路径实例（节点级）
     */
    public AuditRoute selectAuditRouteByAuditRouteId(Long auditRouteId);

    /**
     * 查询审核路径实例（节点级）列表
     * 
     * @param auditRoute 审核路径实例（节点级）
     * @return 审核路径实例（节点级）集合
     */
    public List<AuditRoute> selectAuditRouteList(AuditRoute auditRoute);
    public List<AuditRoute> getNeedCancelRoutes(@Param("businessId") Long businessId,
                                                @Param("auditBusinessType") String auditBusinessType,
                                                @Param("fromOrder") Integer fromOrder,
                                                @Param("toOrder") Integer toOrder);

    List<AuditRoute> selectRollbackCandidates(@Param("businessId") Long businessId,
                                              @Param("auditBusinessType") String auditBusinessType,
                                              @Param("maxOrder") Integer maxOrder);

    List<AuditRoute> selectRollbackTemplates(@Param("businessId") Long businessId,
                                             @Param("auditBusinessType") String auditBusinessType,
                                             @Param("fromOrder") Integer fromOrder,
                                             @Param("toOrder") Integer toOrder);

    void cancelRoutesByOrderRange(@Param("businessId") Long businessId,
                                  @Param("auditBusinessType") String auditBusinessType,
                                  @Param("excludeRouteId") Long excludeRouteId,
                                  @Param("fromOrder") Integer fromOrder,
                                  @Param("toOrder") Integer toOrder,
                                  @Param("status") String status);

    Integer selectMaxRound(@Param("businessId") Long businessId,
                           @Param("auditBusinessType") String auditBusinessType);

    /**
     * 新增审核路径实例（节点级）
     * 
     * @param auditRoute 审核路径实例（节点级）
     * @return 结果
     */
    public int insertAuditRoute(AuditRoute auditRoute);

    /**
     * 修改审核路径实例（节点级）
     * 
     * @param auditRoute 审核路径实例（节点级）
     * @return 结果
     */
    public int updateAuditRoute(AuditRoute auditRoute);

    /**
     * 删除审核路径实例（节点级）
     * 
     * @param auditRouteId 审核路径实例（节点级）主键
     * @return 结果
     */
    public int deleteAuditRouteByAuditRouteId(String auditRouteId);

    /**
     * 批量删除审核路径实例（节点级）
     * 
     * @param auditRouteIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAuditRouteByAuditRouteIds(String[] auditRouteIds);
    
    /**
     * 根据审核业务类型和业务ID查询审核路径实例列表（包含审核人信息）
     * 
     * @param auditBusinessType 审核业务类型
     * @param businessId 业务ID
     * @return 审核路径实例集合
     */
    public List<AuditRoute> selectAuditRoutesByBusinessTypeAndBusinessId(@Param("auditBusinessType") String auditBusinessType,
                                                                         @Param("businessId") Long businessId);
                                                                         
    /**
     * 根据审核业务类型和业务ID查询审核路径实例列表（包含审核人信息），按轮次分组
     *
     * @param auditBusinessType 审核业务类型
     * @param businessId 业务ID
     * @return 审核路径实例集合，按轮次排序
     */
    public List<AuditRoute> selectAuditRoutesByBusinessTypeAndBusinessIdGroupByRound(@Param("auditBusinessType") String auditBusinessType,
                                                                                     @Param("businessId") Long businessId);

    void updateAuditRouteRoundNo(@Param("businessId") Long businessId, @Param("auditBusinessType") String auditBusinessType,
                                 @Param("roundNo") Integer roundNo, @Param("toOrder") Integer toOrder);

    void updatePreAuditRouteRoundNo(@Param("businessId") Long businessId, @Param("auditBusinessType") String auditBusinessType,
                                 @Param("roundNo") Integer roundNo, @Param("fromOrder") Integer fromOrder);
}